package org.jeecg.modules.demo.weixin.smtmerchantshoprecord.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.demo.mall.api.MallHelloApi;
import org.jeecg.modules.demo.mall.dto.ProductNumDto;
import org.jeecg.modules.demo.weixin.entity.SmtMerchantShopRecord;
import org.jeecg.modules.demo.weixin.smtmerchantshoprecord.mapper.SmtMerchantShopRecordMapper;
import org.jeecg.modules.demo.weixin.smtmerchantshoprecord.service.ISmtMerchantShopRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Description: 商家商品表
 * @Author: jeecg-boot
 * @Date:   2023-11-03
 * @Version: V1.0
 */
@Service
public class SmtMerchantShopRecordServiceImpl extends ServiceImpl<SmtMerchantShopRecordMapper, SmtMerchantShopRecord> implements ISmtMerchantShopRecordService {
    @Autowired
    private MallHelloApi mallHelloApi;

    @Override
    public void updateShopRecord(String orderNo) {
        LambdaQueryWrapper<SmtMerchantShopRecord> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SmtMerchantShopRecord::getOrderId, orderNo);
        List<SmtMerchantShopRecord> smtMerchantShopRecords = this.list(lambdaQueryWrapper);
        if (!CollectionUtils.isEmpty(smtMerchantShopRecords)){
            smtMerchantShopRecords.forEach(item -> {
                ProductNumDto productNumDto = new ProductNumDto();
                productNumDto.setProductId(item.getProductId());
                productNumDto.setNum(item.getBuyNum());
                productNumDto.setProductType(item.getProductType());
                productNumDto.setOrderPayType(2);
                productNumDto.setMerStoreId(item.getMerStoreId());
                productNumDto.setSkuId(item.getSkuId());
                mallHelloApi.updateNum(productNumDto);
                item.setShopStatus(2);
                this.updateById(item);
            });
        }


    }
}
